package com.tuozixuan.spring6.resources;

import java.io.InputStream;

import org.springframework.core.io.FileSystemResource;

public class FileSystemResourceDemo {

	public static void loadAndReadUrlResource(String path) throws Exception {
		
		FileSystemResource resource = new FileSystemResource(path);
		// 获取文件名
		System.out.println("resource.getFileName = " + resource.getFilename());
		// 获取文件描述
		System.out.println("resource.getDescription = " + resource.getDescription());
		// 获取文件内容
		InputStream in = resource.getInputStream();
		byte[] b = new byte[1024];
		while (in.read(b) != -1) {
			System.out.println(new String(b));
		}
	}

	public static void main(String[] args) throws Exception {
		
		// 相对路径
		loadAndReadUrlResource("note.txt");
		
		//绝对路径
		loadAndReadUrlResource("D:\\note.txt");
	}
}
